﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace GDI_AnalysisComponents
{
    //图形类

    [Serializable()]
    public class GGraph
    {
        private ArrayList gcs;
        private ArrayList gcSavs;
        private ArrayList gcSels;
        private ArrayList gcSeqLsit;
        private ArrayList lineSavs;
        private ArrayList lineSels;
        private Stack gunStack;
        private MouseEventMode mem;
       
        public GGraph()
        {
            gcs = new ArrayList();
            gcSavs = new ArrayList();
            gcSels = new ArrayList();
            lineSavs = new ArrayList();
            lineSels = new ArrayList();
            gunStack = new Stack();
            gcSeqLsit = new ArrayList();
            mem = MouseEventMode.Normal;
        }

        public void Clear()
        {
           // gcs.Clear();
            gcSavs.Clear();
            gcSels.Clear();
            lineSavs.Clear();
            lineSels.Clear();
            gunStack.Clear();
            gcSeqLsit.Clear();
            mem = MouseEventMode.Normal;
        }

        public ArrayList Gcs
        {
            get { return this.gcs; }
            set { this.gcs = value; }
        }

        public ArrayList GcSavs
        {
            get { return this.gcSavs; }
            set { this.gcSavs = value; }
        }

        public ArrayList GcSels
        {
            get { return this.gcSels; }
            set { this.gcSels = value; }
        }

        public ArrayList GcSeqLsit
        {
            get { return this.gcSeqLsit; }
            set { this.gcSeqLsit = value; }
        }

        public ArrayList LineSavs
        {
            get { return this.lineSavs; }
            set { this.lineSavs = value; }
        }

        public ArrayList LineSels
        {
            get { return this.lineSels; }
            set { this.lineSels = value; }
        }

        public Stack GunStack
        {
            get { return gunStack; }
            set { value = gunStack; }
        }
      
        public MouseEventMode MEM
        {
            get { return mem; }
            set { mem = value; }
        }
 
        //绘制图形
        public void DrawGraphics(Graphics g)
        {
           // lineSavs.Clear();
            //绘组件
            for (int i = 0; i < gcSavs.Count; i++)
            {
                GComponent gc = (GComponent)gcSavs[i];
                gc.DrawGComponent(g);
            }

            //绘连线
            if (lineSavs.Count != 0)
                for (int i = 0; i < lineSavs.Count; i++)
                {
                    GLinkGUnits glg = (GLinkGUnits)lineSavs[i];
                    glg.DrawBlueGLine(g);
                }

            //绘选择组件
            if (gcSels.Count != 0)
                for (int i = 0; i < gcSels.Count; i++)
                {
                    GComponent gc = (GComponent)gcSels[i];
                    gc.DrawGComponent(g);
                    GraphicsPath gp = new GraphicsPath();
                    RectangleF componentRect = gc.GetGComponentRect();
                    gp.AddRectangle(componentRect);
                    Pen pen = new Pen(new SolidBrush(Color.Red), 1);
                    g.DrawPath(pen, gp);
                    PointF[] p = gp.PathPoints;
                    for (int j = 0; j < gp.PointCount; j++)
                    {
                        g.FillRectangle(Brushes.Red, p[j].X - 3, p[j].Y - 3, 6, 6);
                    }
                    gp.Dispose();
                }

            //绘选择线
            if (lineSels.Count!=0)
            for (int i = 0; i < lineSels.Count; i++)
            {
                GLinkGUnits glg = (GLinkGUnits)lineSels[i];            
                glg.DrawRedGLine(g);
            }


            //绘箭头
            if (lineSavs.Count != 0)
                for (int i = 0; i < lineSavs.Count; i++)
                {
                    GLinkGUnits glg = (GLinkGUnits)lineSavs[i];
                    GLine gl = glg.GetGLine();
                    CreateGLine cl = new CreateGLine();
                    double angle = cl.calculateAngle(gl.StartPt, gl.EndPt);                                  
                    Graphics g10 = cl.rotateAngle(g, angle, gl.EndPt);
                    cl.drawArrow(g10, gl.EndPt);
                }
        }
    }
}
